export const factorialIterative = (number: number) => {
  if (number < 0) {
    return undefined;
  }

  let total = 1;

  for (let i = number; i > 1; i--) {
    total *= i;
  }

  return total;
};

/**
 * @description 阶乘递归（尾调用优化）
 * @param number 阶乘数
 * @param total 阶乘结果初始值
 */
export const factorialRecursive = (number: number, total = 1) => {
  if (number >= 0 && number <= 1) {
    return total;
  } else if (number > 1) {
    return factorialRecursive(number - 1, total * number);
  } else {
    return undefined;
  }
};
